package demo7Lianxi20250331;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.sql.SQLOutput;

/**
 * Spring容器管理对象时,一个对象生命周期的对应节点相关操作
 */
@Component
public class Person {
    private String name;

    public Person() {
        System.out.println("1:Person的构造器被调用了");
    }

    public String getName() {
        return name;
    }
@Value("张三")
    public void setName(String name) {
    System.out.println("2:name的set方法调用了,初始化了name属性");
        this.name = name;
    }

    public void play(){
        System.out.println(name+":出去玩");
    }
    @PostConstruct
    public void initial(){
        System.out.println("3:Spring容器将Person对象初始化完毕了,name:"+name);
    }
    @PreDestroy
    public void preDestroy(){
        System.out.println("5:容器要关闭了,通知当前对象");
    }
    //GC调用的销毁无效对象的方法
    public void finalize(){

    }
}
